/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package CtrLayer;
import ModelLayer.*;
import DBLayer.*;
import java.util.ArrayList;

/**
 *
 * @author Sharif
 */
public class CtrProduct {

    public CtrProduct() {

    }

    public ArrayList findAllProducts()
    {
      IFDBProduct dbEmp = new DBProduct();
      ArrayList allEmp = new ArrayList();
      allEmp = dbEmp.getAllProducts(false);
      return allEmp;
    }

    public Product findByName(String name) {
	IFDBProduct dbProd = new DBProduct();
	return dbProd.searchProductName(name, true);
    }

    public Product findById(String id)
    {
        IFDBProduct dbPro = new DBProduct();
        return dbPro.findProduct(id, true);
    }

    public int updateProd(int id, String name, double purchasePrice, double salesPrice, double rentPrice, String countryOfOrigin, int minStock, int supplierid) {
	IFDBProduct dbProd = new DBProduct();
	Product prod = new Product();
        prod.setId(id);
	prod.setName(name);
	prod.setPurchasePrice(purchasePrice);
	prod.setSalesPrice(salesPrice);
	prod.setRentPrice(rentPrice);
	prod.setCountryOfOrigin(countryOfOrigin);
	prod.setMinStock(minStock);
        prod.setSupplierId(supplierid);
	return dbProd.updateProduct(prod);
    }
    
    public int insertNewProd(String name, double purchasePrice, double salesPrice, double rentPrice, String countryOfOrigin, int minStock, int supplierid) {
	IFDBProduct dbProd = new DBProduct();
	Product prod = new Product();
	prod.setName(name);
	prod.setPurchasePrice(purchasePrice);
	prod.setSalesPrice(salesPrice);
	prod.setRentPrice(rentPrice);
	prod.setCountryOfOrigin(countryOfOrigin);
	prod.setMinStock(minStock);
        prod.setSupplierId(supplierid);
	return dbProd.insertProduct(prod);
    }

    public int deleteProduct(int id)
    {
        IFDBProduct dbPro = new DBProduct();
        return dbPro.delete(id);
    }


}
